<?php
/*
 *
 *
echo '<pre>';
print_r($_POST);
echo '</pre>';
 * *
 */
$PageAction = "View";
if (isset($_POST['PME_sys_operation']))
{
    $PageAction = $_POST['PME_sys_operation'];
    if (strtolower($PageAction)=="add")
    {
        $_POST['PME_sys_rec'] = '';
    }
}


$frmUserId = @$_GET['frmUserId'];

if(strlen($frmUserId)>0) {
    $strWhere = " WHERE id = $frmUserId";
}
else
{
    $strWhere = "";
}
$sql = "SELECT * FROM ".$PACTS_cfg->userstablename." ".$strWhere." ORDER BY username ";
//echo "$sql<p><pre>";
$result = mysql_query($sql,$PACTS_cfg->dblink);

echo '<div id="page_header">'."\n";
echo '<ul>'."\n";
echo '<li class="titlename2">'.$PageAction.' Users</li>'."\n";
echo '</ul>'."\n";
echo '</div>'."\n";

if($PACTS_cfg->getUserCanModify()) {


    echo '<div id="details-section">'."\n";
    echo '<div id="RefDataDetailsC1">'."\n";



    ////////////////////////////
    $RefTable = "users";
    $base_page_name = "index.php?view=User_overview";


    //    $opts['RefTable'] = $RefTable;

    $opts['hn'] = $PACTS_cfg->dbserver;// user name
    $opts['un'] = $PACTS_cfg->dbuser;// user name
    $opts['pw'] = $PACTS_cfg->dbpass;//password
    $opts['db'] = $PACTS_cfg->dbname;//database
    $opts['url']['images'] = 'furniture/design/phpMyEditimages/';
    $opts['page_name'] = $base_page_name;

    // Options you wish to give the users
    // A - add,  C - change, P - copy, V - view, D - delete,
    // F - filter, I - initial sort suppressed
    $opts['options'] = 'ACPVDF';
    // Navigation style: B - buttons (default), T - text links, G - graphic links
    // Buttons position: U - up, D - down (default)
    $opts['navigation'] = 'GBU';
    // Display special page elements

    $opts['display'] = array(
    'form'  => true,
    'query' => true,
    'sort'  => false,
    'time'  => false,
    'tabs'  => true
    );
    // Set default prefixes for variables
    $opts['js']['prefix']               = 'PME_js_';
    $opts['dhtml']['prefix']            = 'PME_dhtml_';
    $opts['cgi']['prefix']['operation'] = 'PME_op_';
    $opts['cgi']['prefix']['sys']       = 'PME_sys_';
    $opts['cgi']['prefix']['data']      = 'PME_data_';

/* Get the user's default language and use it if possible or you can
   specify particular one you want to use. Refer to official documentation
   for list of available languages. */
    $opts['language'] = $_SERVER['HTTP_ACCEPT_LANGUAGE'] . '-UTF8';
    // Number of records to display on the screen
    // Value of -1 lists all records in a table
    $opts['inc'] = 15;


    // Number of lines to display on multiple selection filters
    $opts['multiple'] = '4';

    /////////////////////////////////////
    $opts['tb'] = 'UserData';
    $opts['tb'] = 'Users';

    // Name of field which is the unique key
    $opts['key'] = 'UserName';

    // Type of key field (int/real/string/date etc.)
    $opts['key_type'] = 'string';

    // Sorting field(s)
    $opts['sort_field'] = array('UserName');

    $opts['fdd']['UserName'] = array(
  'name'     => 'UserName',
  'default'  => '[username]',
  'select'   => 'T',
  'maxlen'   => 40,
  'colattrs' => 'align="center"',
  'sort'     => true
    );

    $opts['fdd']['pw'] = array(
  'name'     => 'Password',
  'default'  => '',
  'input'      => 'W',
  'select'   => 'T',
  'options'    => 'ACPVD',
  'required'   => true,
  'maxlen'   => 40,
  'size|ACP'   => 20,
  'sort'       => false,
  'sqlw'       => 'IF(pw = $val_qas, $val_qas, MD5($val_qas))',
    );
    $opts['fdd']['Group'] = array(
  'name'     => 'Group',
  'select'   => 'T',
  'default' => 'Editor',
  'maxlen'   => 50,
  'sort'     => true
    );
    $opts['fdd']['Group']['values']['table']   = 'UserGroup';
    $opts['fdd']['Group']['values']['column']   =  'GroupName';



    $opts['fdd']['Enabled'] = array(
  'name'     => 'Enabled',
  'select'   => 'T',
  'maxlen'   => 1,
  'values'   => array(
                  "Y",
                  "N"),
  'default'  => 'Y',
  'colattrs' => 'align="center"',
  'sort'     => true
    );
    $opts['fdd']['EmailAddress'] = array(
  'name'     => 'EmailAddress',
  'select'   => 'T',
  'maxlen'   => 150,
  'default' => ' ',
  'sort'     => true
    );
    $opts['fdd']['LoginCount'] = array(
  'name'     => 'LoginCount',
  'select'   => 'T',
  'input'   => 'R',
  'maxlen'   => 5,
  'default' =>  0,
  'colattrs' => 'align="center"',
  'sort'     => true
    );
    $opts['fdd']['EditCount'] = array(
  'name'     => 'EditCount',
  'select'   => 'T',
  'input'   => 'R',
  'maxlen'   => 5,
  'default' =>  0,
  'colattrs' => 'align="center"',
  'sort'     => true
    );
    $opts['fdd']['LastLoginTMS'] = array(
  'name'     => 'LastLoginTMS',
  'select'   => 'T',
  'options'  => 'AVCPDR', // updated automatically (MySQL feature)
  'maxlen'   => 19,
  'sort'     => true
    );
    // Now important call to phpMyEdit


    /////////////////////////////////////
    echo '<div class="phpMyEdit-section-users">'."\n";

    new phpMyEdit($opts);

    echo '</div>'."\n";

    echo '</div>'."\n";
    echo '</div>'."\n";

} else
{
    echo '<div id="details-section">'."\n";
    echo '<div id="viewDetailsC2">'."\n";

    echo '<p class="errmsg1">Error! You do not have permission to administer the system!</p>'."\n";
    echo '</div>'."\n";
    echo '</div>'."\n";

}

?>